#ifndef __THREADMANAGER_H__
#define __THREADMANAGER_H__

#include "base/threads/PthreadInterface.h"
#include "util/Logger.h"

class ThreadManager {
  public:
    NEW_DELETE_OPERATORS_H(ThreadManager,NoSuper);
    ThreadManager (int num_cpus);
    ~ThreadManager ();

    int getNewTID (int procID);
    int getProcID (int threadID);
    bool isEnded (int threadID);

    void setPthreadInterfaceSim (PthreadInterface*);
    void goto_real ();
    void goto_sim ();

    Logger threadLog;

    //    static bool isa_ext_set_fork_addr (Processor* P, Reg arg0, Reg arg1, Reg* result);
    static bool isa_ext_fork (Processor* P, Reg arg0, Reg arg1, Reg* result);
    static bool isa_ext_threadid (Processor* P, Reg arg0, Reg arg1, Reg* result);
    static bool isa_ext_thexit (Processor* P, Reg arg0, Reg arg1, Reg* result);
    static bool isa_ext_thend (Processor* P, Reg arg0, Reg arg1, Reg* result);
    static bool isa_ext_sigthread (Processor* P, Reg arg0, Reg arg1, Reg* result);

  private:
    int num_cpus;
    int* TIDCounter;
    
    PthreadInterface* pthreadInterfaceReal;
    PthreadInterface* pthreadInterfaceSim;
};

#endif // __THREADMANAGER_H__
